import { $post, $get, $delete, $put } from "@/utils/request";

// 获取药品列表
export const $DrugList = async () => {
    return await $post("/drug/Inquire");
}

// 获取药品详情
export const $DrugDetail = async (params: object) => {
    const { id } = params;
    return await $post(`/drug/InquireId?id=${id}`);
}

// 获取药品分类
export const $DrugType = async (params: object) => {
    const { classification } = params;
    return await $post(`/drug/Department?classification=${classification}`);
}

// 搜索药品
export const $Search = async (params: object) => {
    const { data } = params;
    return await $post(`/drug/data?data=${data}`);
}

// 删除药品信息
export const $DeleteDrug = async (params: object) => {
    const queryParams = params.map(id => `ids=${id}`).join('&');
    return await $delete(`/drug/deleteDrug?${queryParams}`)
}

// 添加药品信息
export const $InsertDrug = async (params: object) => {
    const { name, classification, company, url, function1, components, usageDosage, precautions, adverse } = params
    return await $post(`/drug/insertDrug?name=${name}&classification=${classification}&company=${company}&url=${url}&function=${function1}&components=${components}&usageDosage=${usageDosage}&precautions=${precautions}&adverse=${adverse}`)
}

// 修改药品信息
export const $UpdateDrug = async (params: object) => {
    const { id, name, classification, company, url, function1, components, usageDosage, precautions, adverse } = params
    return await $put(`/drug/updateDrug?id=${id}&name=${name}&classification=${classification}&company=${company}&url=${url}&function=${function1}&components=${components}&usageDosage=${usageDosage}&precautions=${precautions}&adverse=${adverse}`)
}